/*
 * Copyright 2011-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sabayframework.activity.impl;

import org.sabayframework.activity.Activity;
import org.sabayframework.activity.ActivityContext;

/**
 * Delegating activity is useful when you need to override default behavior of
 * an existing activity. 
 * 
 * @author Alex Antonau
 * */
public class DelegatingActivity<I, O> implements Activity<I, O> {
	private Activity<I, O> delegate;

	protected DelegatingActivity() {
		super();
	}

	public DelegatingActivity(Activity<I, O> delegate) {
		super();
		this.delegate = delegate;
	}

	public Activity<I, O> getDelegate() {
		return delegate;
	}

	protected void setDelegate(Activity<I, O> delegate) {
		this.delegate = delegate;
	}

	public void execute(ActivityContext<I, O> ctx) throws Exception {
		delegate.execute(ctx);
	}

	public void beforeExecute(ActivityContext<I, O> ctx) throws Exception {
		delegate.beforeExecute(ctx);
	}

	public void afterExecute(ActivityContext<I, O> ctx) throws Exception {
		delegate.afterExecute(ctx);
	}

	public boolean isReady(ActivityContext<I, O> ctx) throws Exception {
		return delegate.isReady(ctx);
	}

	public boolean isDone(ActivityContext<I, O> ctx) throws Exception {
		return delegate.isDone(ctx);
	}

	@Override
	public String toString() {
		return "DelegatingActivity [delegate=" + delegate + "]";
	}

	@Override
	public int hashCode() {
		return delegate.hashCode();
	}
	@Override
	public boolean equals(Object obj){
		return delegate.equals(obj);
	}
}
